package com.zx.article.article.service.impl;

import java.util.List;

import com.zx.article.article.dao.IArticleDao;
import com.zx.article.article.dao.impl.ArticleDaoImpl;
import com.zx.article.article.model.ArticleModel;
import com.zx.article.article.service.IArticleService;
import com.zx.article.reviewRecords.service.impl.ReviewRecordsServiceImpl;

public class ArticleServiceImpl implements IArticleService {

	private IArticleDao articleDao = new ArticleDaoImpl();

	@Override
	public String add(ArticleModel articleModel) {
		return "1".equals(articleDao.insert(articleModel)) ? "success" : "fail";
	}

	@Override
	public int getCount(ArticleModel articleModel) {
		articleModel.setTitle(articleModel.getTitle() == null ? null : "%" + articleModel.getTitle() + "%");
		articleModel.setKey(articleModel.getKey() == null ? null : "%" + articleModel.getKey() + "%");
		articleModel.setAuthor(articleModel.getAuthor() == null ? null : "%" + articleModel.getAuthor() + "%");
		return articleDao.getCount(articleModel);
	}

	@Override
	public List<ArticleModel> getList(ArticleModel articleModel) {
		return articleDao.getList(articleModel);
	}

	@Override
	public String del(Integer id) {
		new ReviewRecordsServiceImpl().del(id);
		return "1".equals(articleDao.delete(id)) ? "success" : "fail";
	}

	@Override
	public ArticleModel getModel(Integer id) {
		return articleDao.queryOne(id);
	}

	@Override
	public String upd(ArticleModel articleModel) {
		return "1".equals(articleDao.updata(articleModel)) ? "success" : "fail";
	}

	@Override
	public int getCaseCount(ArticleModel articleModel) {
		articleModel.setTitle(articleModel.getTitle() == null ? null : "%" + articleModel.getTitle() + "%");
		articleModel.setAuthor(articleModel.getAuthor() == null ? null : "%" + articleModel.getAuthor() + "%");
		return articleDao.getCaseCount(articleModel);
	}

	@Override
	public List<ArticleModel> getCaseList(ArticleModel articleModel) {
		return articleDao.getCaseList(articleModel);
	}

}
